
/**
 * 拼接sql语句 如where后面的句子 或 insert、update 的 () 内
 * @param {String} str 原sql语句
 * @param {Array} params 数组/对象参数
 * @param {String} splice 拼接字段
 * @returns 
 */

let mysql = require('mysql');

exports.paramsSplicing = (str, params, splice) => {
    for (let key in params) {
        if (!(params[key] === "" || params[key] === null || params[key] === undefined)) {
            str += " " + key + "=" + mysql.escape(params[key]) + " " + splice
        }
    }
    str = str.substring(0, str.length - splice.length);
    return str;
}